package SoketServer;

import javax.naming.ldap.SortKey;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException{

        ServerSocket serverSocket = new ServerSocket(10086);
        Socket socket = serverSocket.accept();//接收客户端的请求，如果没有请求就会一直在这里等待请求，监听10086端口
        DataInputStream dis = new DataInputStream(new BufferedInputStream(socket.getInputStream()));//接收客户端
        DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));//向客户端输出
        do {
            double length = dis.readDouble();
            System.out.println("从客户端接收到的边长为：" + length);
            double result = length * length;
            dos.writeDouble(result);
            dos.flush();
        }while(dis.readInt()!=0);
        socket.close();
        serverSocket.close();
    }
}
